package com.charity.service.impl;

import com.charity.domain.Project;
import com.charity.mapper.ProjectMapper;
import com.charity.service.IProjectService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
@Primary
public class ProjectServiceImpl implements IProjectService {

    @Resource
    private ProjectMapper projectMapper;

    @Override
    public boolean createProject(Project project) {
        return projectMapper.insert(project) > 0;
    }

    @Override
    public boolean updateProject(Project project) {
        return projectMapper.updateById(project) > 0;
    }

    @Override
    public boolean deleteProject(Long projectId) {
        return projectMapper.deleteById(projectId) > 0;
    }

    @Override
    public Project getProjectById(Long projectId) {
        return projectMapper.selectById(projectId);
    }

    @Override
    public List<Project> getProjectList(Integer status, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return projectMapper.selectList(status, offset, pageSize);
    }

    @Override
    public boolean updateProjectStatus(Long projectId, Integer status) {
        Project project = new Project();
        project.setProjectId(projectId);
        return projectMapper.updateById(project) > 0;
    }
}